import { defineConfig } from "vite";
const copy = require("rollup-plugin-copy");
import dts from "vite-plugin-dts";

export default defineConfig({
  plugins: [
    dts({
      entryRoot: "./src",
      outDir: ["./dist/cjs", "./dist/es"],
      tsconfigPath: "./tsconfig.json",
    }),
  ],
  build: {
    lib: {
      entry: "./src/index.ts",
      // fileName: "leisure-lib",
      // name: "LeisureLib",
    },
    rollupOptions: {
      external: [/@leisure-lib.*/, "vue"],
      output: [
        {
          format: "es",
          entryFileNames: "[name].mjs",
          preserveModules: true,
          exports: "named",
          dir: "./dist/es",
        },
        {
          format: "cjs",
          entryFileNames: "[name].js",
          preserveModules: true,
          exports: "named",
          dir: "./dist/cjs",
        },
      ],
      plugins: [
        copy({
          targets: [{ src: "style/**", dest: "dist/style" }],
          hook: "writeBundle",
        }),
      ],
    },
  },
});
